<%@page language="java" contentType="text/html; character=UTF-8" pageEncoding="UTF-8" %>
<%@include file="/taglibs.jsp"%>
<%
String path = request.getContextPath();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="pragma" content="no-cache" />
		<meta http-equiv="cache-control" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
		<meta http-equiv="description" content="This is my page" />

		<link rel="stylesheet" type="text/css" href="<%=path %>/css/base.css" />
		
        <script language="javascript">
           function hangbanDel(id)
           {
               if(confirm('您确定删除吗？'))
               {
				   $.get(
						   '${ctx}/hangban/deleteHangban/'+id,
						   function (obj) {
							   // layer.msg(obj.message,{time:600})
							   alert(obj.message)
							   if (obj.success){
								   changeSearch(${pagers.current})
							   }
						   }
				   )
               }
           }
           
           function hangbanAdd()
           {
                 var url="${ctx}/hangban/toAddHangban";
				 window.location.href=url;
           }
           
       </script>
	</head>

	<body leftmargin="2" topmargin="2">
	<ul class="search" style="padding-left: 10px;">
		<li>
			<input type="text" id="input_start" placeholder="起始地" name="startPlace" class="input" value="${obj.shifadi}"
				   style="width: 250px;line-height: 17px;display: inline-block" />
			<input type="text" id="input_end" placeholder="目的地" name="endPlace" class="input" value="${obj.daodadi}"
				   style="width: 250px;line-height: 17px;display: inline-block" />
			<a href="javascript:void(0)" onclick="changeSearch(1)" class="button border-main icon-search">搜索</a>
		</li>
	</ul>
			<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">
				<tr bgcolor="#E7E7E7">
					<td height="14" colspan=18" background="<%=path %>/img/tbg.jpg">&nbsp;&nbsp;</td>
				</tr>
				<tr align="center" bgcolor="#FAFAF1" height="22">
					<td width="4%">序号</td>
					
					<td width="9%">航班日期</td>
					<td width="9%">航班编号</td>
					<td width="9%">始发地点</td>
					<td width="9%">到达地点</td>
					
					<td width="9%">起飞时间</td>
					<td width="9%">剩余票数</td>
					<td width="9%">成人票价</td>
					
					<td width="9%">儿童票价</td>
					<td width="9%">操作</td>
		        </tr>	
				<c:forEach items="${pagers.records}" var="hangban" varStatus="ss">
				<tr align='center' bgcolor="#FFFFFF" onMouseMove="javascript:this.bgColor='red';" onMouseOut="javascript:this.bgColor='#FFFFFF';" height="22">
					<td bgcolor="#FFFFFF" align="center">
						 ${ss.index+1}
					</td>
					
					<td bgcolor="#FFFFFF" align="center">
						 ${hangban.riqi}
					</td>
					<td bgcolor="#FFFFFF" align="center">
						 ${hangban.bianhao}
					</td>
					<td bgcolor="#FFFFFF" align="center">
						 ${hangban.shifadi}
					</td>
					<td bgcolor="#FFFFFF" align="center">
						 ${hangban.daodadi}
					</td>
					
					<td bgcolor="#FFFFFF" align="center">
						 ${hangban.qifeishi}
					</td>
					<td bgcolor="#FFFFFF" align="center">
						 ${hangban.shengpiao}
					</td>
					<td bgcolor="#FFFFFF" align="center">
						 ${hangban.chengrenpiaojia}
					</td>
					
					<td bgcolor="#FFFFFF" align="center">
						 ${hangban.ertongpiaojia}
					</td>
					<td bgcolor="#FFFFFF" align="center">
						<input type="button" value="删除" onclick="hangbanDel(${hangban.id})"/>
					</td>
				</tr>
				</c:forEach>
				<tr>
					<td colspan="8">
						<div class="pagelist">
							<pg:pager >
								<pg:last>
									共${pagers.total}记录，共${pagers.pages}页，
								</pg:last>
								当前第${pagers.current}页
								<pg:first>
									<c:choose>
										<c:when test="${pagers.current > 1}">
											<a onclick="changeSearch(1)">首页</a>
										</c:when>
									</c:choose>
								</pg:first>
								<pg:prev>
									<c:choose>
										<c:when test="${pagers.current > 1}">
											<a onclick="changeSearch(${pagers.current-1})">上一页</a>
										</c:when>
									</c:choose>
								</pg:prev>
								<pg:pages>
									<c:choose>
										<c:when test="${pagers.pages<4}">
											<c:set var="begin" value="1"/>
											<c:set var="end" value="${pagers.pages}"/>
										</c:when>
										<c:otherwise>
											<c:set var="begin" value="${pagers.current-1}"/>
											<c:set var="end" value="${pagers.current+1}"/>
											<c:if test="${begin<1}">
												<c:set var="begin" value="1"/>
												<c:set var="end" value="3"/>
											</c:if>
											<c:if test="${end>pagers.pages}">
												<c:set var="begin" value="${pagers.pages-2}"/>
												<c:set var="end" value="${pagers.pages}"/>
											</c:if>
										</c:otherwise>
									</c:choose>
									<c:forEach begin="${begin}" end="${end}" var="pageNum">
										<c:choose>
											<c:when test="${pageNum eq pagers.current}">
												<a style="background: dodgerblue" onclick="changeSearch(${pageNum})">${pageNum}</a>
											</c:when>
											<c:otherwise>
												<a onclick="changeSearch(${pageNum})">${pageNum}</a>
											</c:otherwise>
										</c:choose>
									</c:forEach>
								</pg:pages>
								<pg:next>
									<c:choose>
										<c:when test="${pagers.current < pagers.pages}">
											<a onclick="changeSearch(${pagers.current+1})">下一页</a>
										</c:when>
									</c:choose>
								</pg:next>
								<pg:last>
									<c:choose>
										<c:when test="${pagers.current eq pagers.pages}">
											<%--                                    <font color="red">尾页</font>--%>
										</c:when>
										<c:otherwise>
											<a onclick="changeSearch(${pagers.pages})">尾页</a>
										</c:otherwise>
									</c:choose>
								</pg:last>
							</pg:pager>
						</div>
					</td>
				</tr>
			</table>
			
			<table width='98%'  border='0'style="margin-top:8px;margin-left: 8px;">
			  <tr>
			    <td>
			      <input type="button" value="添加航班信息" style="width: 80px;" onclick="hangbanAdd()" />
			    </td>
			  </tr>
		    </table>
			<script>
				function changeSearch(current){
					var inputStart = $("#input_start").val().trim()
					console.log(inputStart)
					var inputEnd = $("#input_end").val().trim()
					console.log(inputEnd)
					window.location.href='${ctx}/hangban/getHangbanList/'+current+'/6?shifadi='+inputStart+'&daodadi='+inputEnd
				}
			</script>
	</body>
</html>
